package com.yuzhi.master.locations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/locations")
public class PolygonController {

    @Autowired
    private LocationService locationService;

    @PostMapping
    public ResponseEntity<String> createLocation(@RequestBody Location location) {
        try {
            Long generatedId = locationService.saveLocation(location);
            return ResponseEntity.ok("位置数据创建成功，ID: " + generatedId);
        } catch (IllegalArgumentException e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        } catch (Exception e) {
            return ResponseEntity.internalServerError().body("服务器错误: " + e.getMessage());
        }
    }
}
